<% page_title "Secrets" %>
<h1>
  Secrets
  <%= render "header" %>
</h1>

<%= search_form('data-secret-base': Samson::Secrets::Manager::VALUE_HASHED_BASE) do %>
  <%= search_select :environment_permalink, @environment_permalinks, live: true, label: "Environment" %>
  <%= search_select :project_permalink, @project_permalinks, live: true, label: "Project" %>
  <%= search_select :deploy_group_permalink, @deploy_group_permalinks, live: true, label: "Deploy Group" %>
  <%= search_select :key, @keys, live: true %>

  <div class="col-sm-2">
    <% if duplicate = params.dig(:search, :value_from) %>
      <%= label_tag "Duplicates of" %>
      <%= text_field_tag 'search[value_from]', duplicate, class: "form-control" %>
    <% else %>
      <%# Using value as field so if javascript hashing breaks the value is not logged. %>
      <%= label_tag "Value" %>
      <%= password_field_tag 'search[value_hashed]', params.dig(:search, :value_hashed), class: "form-control" %>
    <% end %>
  </div>
<% end %>

<section class="clearfix">
  <table class="table table-hover table-condensed">
    <thead>
      <tr>
        <th>Environment</th>
        <th>Project</th>
        <th>Deploy Group</th>
        <th>Key <%= additional_info "To use a key in commands, prefix with #{TerminalExecutor::SECRET_PREFIX}" %></th>
        <th><%= link_to "New", new_secret_path, class: "btn btn-default" %></th>
      </tr>
    </thead>

    <tbody>
      <% @secrets.each do |id, parts, secret_stub| %>
        <%= render "row", id: id, parts: parts, secret_stub: secret_stub %>
      <% end %>
    </tbody>
  </table>

  <div class="admin-actions">
    <%= paginate @pagy %>
  </div>
</section>
